module.exports = function(app) {
  return new Handler(app)
}

var Handler = function(app) {
  this.app = app
  Handler.app = app
  this.sessionService = this.app.get('sessionService')
  this.channelService = this.app.get('channelService')
  this.gameChanel = this.channelService.getChannel("GameChannel",true)
}

var handler = Handler.prototype



//获取答题历史记录
handler.getAnswerHistory = function(msg,session,next) {
	var uid = session.get("uid")
	if(!!uid){
		this.app.rpc.db.gameInfo.getAnswerHistory(null,msg.dayStr,function(flag,msg) {
			next(null,{flag : flag,msg : msg})
		})
	}else{
		next(null,{flag : false,msg : "未登录"})
	}
}

//获取答题信息
handler.getAnswerInfo = function(msg,session,next) {
	var uid = session.get("uid")
	if(!!uid){
		this.app.rpc.db.gameInfo.getAnswerInfo(null,uid,function(flag,msg) {
			next(null,{flag : flag,msg : msg})
		})
	}else{
		next(null,{flag : false,msg : "未登录"})
	}
}
//获取账号信息
handler.getAccountInfo = function(msg,session,next) {
	var uid = session.get("uid")
	if(!!uid){
		this.app.rpc.db.gameInfo.getAccountInfo(null,uid,function(flag,msg) {
			next(null,{flag : flag,msg : msg})
		})
	}else{
		next(null,{flag : false,msg : "未登录"})
	}
}

//获取排行榜记录
handler.getRankingRecord = function(msg,session,next) {
	var gameType = msg.gameType
	if(!gameType){
		next(null,{flag : false,msg : "gameType error"})
		return
	}
	var uid = session.get("uid")
	if(!!uid){
		this.app.rpc.db.gameInfo.getRankingRecord(null,gameType,function(flag,msg) {
			next(null,{flag : flag,msg : msg})
		})
	}else{
		next(null,{flag : false,msg : "未登录"})
	}
}

//获取个人记录
handler.getUserRecord = function(msg,session,next) {
	var gameType = msg.gameType
	if(!gameType){
		next(null,{flag : false,msg : "gameType error"})
		return
	}
	var uid = session.get("uid")
	if(!!uid){
		this.app.rpc.db.gameInfo.getUserRecord(null,uid,gameType,function(flag,msg) {
			next(null,{flag : flag,msg : msg})
		})
	}else{
		next(null,{flag : false,msg : "未登录"})
	}
}